import { Block, BlockType, ToolType } from './types';

export const BLOCK_REGISTRY: Partial<Record<BlockType, Block>> = {
  [BlockType.AIR]: {
    id: BlockType.AIR,
    name: '空气',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {}
  },
  [BlockType.GRASS]: {
    id: BlockType.GRASS,
    name: '草方块',
    solid: true,
    properties: {
      hardness: 0.6,
      tool: ToolType.SHOVEL,
      drops: [{ type: BlockType.DIRT, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'grass_top',
      bottom: 'dirt',
      sides: 'grass_side'
    }
  },
  [BlockType.DIRT]: {
    id: BlockType.DIRT,
    name: '泥土',
    solid: true,
    properties: {
      hardness: 0.5,
      tool: ToolType.SHOVEL,
      drops: [{ type: BlockType.DIRT, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'dirt',
      bottom: 'dirt',
      sides: 'dirt'
    }
  },
  [BlockType.STONE]: {
    id: BlockType.STONE,
    name: '石头',
    solid: true,
    properties: {
      hardness: 1.5,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.COBBLESTONE, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'stone',
      bottom: 'stone',
      sides: 'stone'
    }
  },
  [BlockType.LOG]: {
    id: BlockType.LOG,
    name: '原木',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.AXE,
      drops: [{ type: BlockType.LOG, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'log_top',
      bottom: 'log_top',
      sides: 'log_side'
    }
  },
  [BlockType.PLANKS]: {
    id: BlockType.PLANKS,
    name: '木板',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.AXE,
      drops: [{ type: BlockType.PLANKS, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'planks',
      bottom: 'planks',
      sides: 'planks'
    }
  },
  [BlockType.COAL_ORE]: {
    id: BlockType.COAL_ORE,
    name: '煤矿',
    solid: true,
    properties: {
      hardness: 3.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.COAL_ITEM, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'coal_ore',
      bottom: 'coal_ore',
      sides: 'coal_ore'
    }
  },
  [BlockType.LAVA]: {
    id: BlockType.LAVA,
    name: '岩浆',
    solid: false,
    properties: {
      hardness: 100,
      drops: [],
      transparent: false,
      lightLevel: 15,
      liquid: true
    },
    textures: {
      top: 'lava',
      bottom: 'lava',
      sides: 'lava'
    }
  },
  [BlockType.FURNACE]: {
    id: BlockType.FURNACE,
    name: '熔炉',
    solid: true,
    properties: {
      hardness: 3.5,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.FURNACE, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'furnace_top',
      bottom: 'furnace_top',
      front: 'furnace_front',
      sides: 'furnace_side'
    }
  },
  [BlockType.TORCH]: {
    id: BlockType.TORCH,
    name: '火把',
    solid: false,
    properties: {
      hardness: 0,
      drops: [{ type: BlockType.TORCH, count: 1, chance: 1.0 }],
      transparent: true,
      lightLevel: 14
    },
    textures: {
      sides: 'torch'
    }
  },
  [BlockType.CRAFTING_TABLE]: {
    id: BlockType.CRAFTING_TABLE,
    name: '工作台',
    solid: true,
    properties: {
      hardness: 2.5,
      tool: ToolType.AXE,
      drops: [{ type: BlockType.CRAFTING_TABLE, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'crafting_table_top',
      bottom: 'planks',
      front: 'crafting_table_front',
      sides: 'crafting_table_side'
    }
  },
  // 新增方块
  [BlockType.SAND]: {
    id: BlockType.SAND,
    name: '沙子',
    solid: true,
    properties: {
      hardness: 0.5,
      tool: ToolType.SHOVEL,
      drops: [{ type: BlockType.SAND, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'sand',
      bottom: 'sand',
      sides: 'sand'
    }
  },
  [BlockType.SANDSTONE]: {
    id: BlockType.SANDSTONE,
    name: '砂岩',
    solid: true,
    properties: {
      hardness: 0.8,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.SANDSTONE, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'sandstone_top',
      bottom: 'sandstone_bottom',
      sides: 'sandstone_side'
    }
  },
  [BlockType.GLASS]: {
    id: BlockType.GLASS,
    name: '玻璃',
    solid: true,
    properties: {
      hardness: 0.3,
      drops: [], // 玻璃破碎后不掉落
      transparent: true,
      lightLevel: 0
    },
    textures: {
      top: 'glass',
      bottom: 'glass',
      sides: 'glass'
    }
  },
  [BlockType.IRON_ORE]: {
    id: BlockType.IRON_ORE,
    name: '铁矿',
    solid: true,
    properties: {
      hardness: 3.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.RAW_IRON, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'iron_ore',
      bottom: 'iron_ore',
      sides: 'iron_ore'
    }
  },
  [BlockType.GOLD_ORE]: {
    id: BlockType.GOLD_ORE,
    name: '金矿',
    solid: true,
    properties: {
      hardness: 3.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.RAW_GOLD, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'gold_ore',
      bottom: 'gold_ore',
      sides: 'gold_ore'
    }
  },
  [BlockType.DIAMOND_ORE]: {
    id: BlockType.DIAMOND_ORE,
    name: '钻石矿',
    solid: true,
    properties: {
      hardness: 3.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.DIAMOND, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'diamond_ore',
      bottom: 'diamond_ore',
      sides: 'diamond_ore'
    }
  },
  [BlockType.WATER]: {
    id: BlockType.WATER,
    name: '水',
    solid: false,
    properties: {
      hardness: 100,
      drops: [],
      transparent: true,
      lightLevel: 0,
      liquid: true
    },
    textures: {
      top: 'water',
      bottom: 'water',
      sides: 'water'
    }
  },
  [BlockType.OBSIDIAN]: {
    id: BlockType.OBSIDIAN,
    name: '黑曜石',
    solid: true,
    properties: {
      hardness: 50.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.OBSIDIAN, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'obsidian',
      bottom: 'obsidian',
      sides: 'obsidian'
    }
  },
  [BlockType.REDSTONE_WIRE]: {
    id: BlockType.REDSTONE_WIRE,
    name: '红石线',
    solid: false,
    properties: {
      hardness: 0,
      drops: [{ type: BlockType.REDSTONE_WIRE, count: 1, chance: 1.0 }],
      transparent: true,
      lightLevel: 0,
      redstoneConductive: true
    },
    textures: {
      top: 'redstone_wire',
      bottom: 'redstone_wire',
      sides: 'redstone_wire'
    }
  },
  [BlockType.REDSTONE_TORCH]: {
    id: BlockType.REDSTONE_TORCH,
    name: '红石火把',
    solid: false,
    properties: {
      hardness: 0,
      drops: [{ type: BlockType.REDSTONE_TORCH, count: 1, chance: 1.0 }],
      transparent: true,
      lightLevel: 7,
      redstoneConductive: true
    },
    textures: {
      sides: 'redstone_torch'
    }
  },
  [BlockType.COBBLESTONE]: {
    id: BlockType.COBBLESTONE,
    name: '圆石',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.COBBLESTONE, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'cobblestone',
      bottom: 'cobblestone',
      sides: 'cobblestone'
    }
  },
  [BlockType.GRAVEL]: {
    id: BlockType.GRAVEL,
    name: '沙砾',
    solid: true,
    properties: {
      hardness: 0.6,
      tool: ToolType.SHOVEL,
      drops: [
        { type: BlockType.GRAVEL, count: 1, chance: 0.9 },
        { type: BlockType.GRAVEL, count: 1, chance: 0.1 } // 简化的燧石掉落
      ],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'gravel',
      bottom: 'gravel',
      sides: 'gravel'
    }
  },
  [BlockType.CLAY]: {
    id: BlockType.CLAY,
    name: '粘土',
    solid: true,
    properties: {
      hardness: 0.6,
      tool: ToolType.SHOVEL,
      drops: [{ type: BlockType.CLAY, count: 4, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'clay',
      bottom: 'clay',
      sides: 'clay'
    }
  },
  [BlockType.BRICK]: {
    id: BlockType.BRICK,
    name: '砖块',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.PICKAXE,
      drops: [{ type: BlockType.BRICK, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'brick',
      bottom: 'brick',
      sides: 'brick'
    }
  },
  [BlockType.SNOW]: {
    id: BlockType.SNOW,
    name: '雪',
    solid: true,
    properties: {
      hardness: 0.1,
      tool: ToolType.SHOVEL,
      drops: [{ type: BlockType.SNOW, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0
    },
    textures: {
      top: 'snow',
      bottom: 'snow',
      sides: 'snow'
    }
  },
  // 物品类型（不可放置的方块）
  [BlockType.COAL_ITEM]: {
    id: BlockType.COAL_ITEM,
    name: '煤炭',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'coal_item'
    }
  },
  [BlockType.LEAVES]: {
    id: BlockType.LEAVES,
    name: '树叶',
    solid: true,
    properties: {
      hardness: 0.2,
      tool: ToolType.NONE,
      drops: [
        { type: BlockType.SAPLING, count: 1, chance: 0.05 },
        { type: BlockType.LEAVES, count: 1, chance: 0.95 }
      ],
      transparent: true,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'leaves',
      bottom: 'leaves',
      sides: 'leaves'
    }
  },
  [BlockType.BIRCH_LOG]: {
    id: BlockType.BIRCH_LOG,
    name: '白桦原木',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.AXE,
      drops: [{ type: BlockType.BIRCH_LOG, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'birch_log_top',
      bottom: 'birch_log_top',
      sides: 'birch_log_side'
    }
  },
  [BlockType.SPRUCE_LOG]: {
    id: BlockType.SPRUCE_LOG,
    name: '云杉原木',
    solid: true,
    properties: {
      hardness: 2.0,
      tool: ToolType.AXE,
      drops: [{ type: BlockType.SPRUCE_LOG, count: 1, chance: 1.0 }],
      transparent: false,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'spruce_log_top',
      bottom: 'spruce_log_top',
      sides: 'spruce_log_side'
    }
  },
  [BlockType.BIRCH_LEAVES]: {
    id: BlockType.BIRCH_LEAVES,
    name: '白桦树叶',
    solid: true,
    properties: {
      hardness: 0.2,
      tool: ToolType.NONE,
      drops: [
        { type: BlockType.SAPLING, count: 1, chance: 0.05 },
        { type: BlockType.BIRCH_LEAVES, count: 1, chance: 0.95 }
      ],
      transparent: true,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'birch_leaves',
      bottom: 'birch_leaves',
      sides: 'birch_leaves'
    }
  },
  [BlockType.SPRUCE_LEAVES]: {
    id: BlockType.SPRUCE_LEAVES,
    name: '云杉树叶',
    solid: true,
    properties: {
      hardness: 0.2,
      tool: ToolType.NONE,
      drops: [
        { type: BlockType.SAPLING, count: 1, chance: 0.05 },
        { type: BlockType.SPRUCE_LEAVES, count: 1, chance: 0.95 }
      ],
      transparent: true,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      top: 'spruce_leaves',
      bottom: 'spruce_leaves',
      sides: 'spruce_leaves'
    }
  },
  [BlockType.WET_LEAVES]: {
    id: BlockType.WET_LEAVES,
    name: '含水树叶',
    solid: true,
    properties: {
      hardness: 0.2,
      tool: ToolType.NONE,
      drops: [
        { type: BlockType.SAPLING, count: 1, chance: 0.05 },
        { type: BlockType.LEAVES, count: 1, chance: 0.95 }
      ],
      transparent: true,
      lightLevel: 0,
      flammable: false
    },
    textures: {
      top: 'wet_leaves',
      bottom: 'wet_leaves',
      sides: 'wet_leaves'
    }
  },
  [BlockType.SAPLING]: {
    id: BlockType.SAPLING,
    name: '树苗',
    solid: false,
    properties: {
      hardness: 0,
      drops: [{ type: BlockType.SAPLING, count: 1, chance: 1.0 }],
      transparent: true,
      lightLevel: 0,
      flammable: true
    },
    textures: {
      sides: 'sapling'
    }
  },
  [BlockType.ENDER_PEARL]: {
    id: BlockType.ENDER_PEARL,
    name: '末影珍珠',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'ender_pearl'
    }
  },
  [BlockType.IRON_INGOT]: {
    id: BlockType.IRON_INGOT,
    name: '铁锭',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'iron_ingot'
    }
  },
  [BlockType.GOLD_INGOT]: {
    id: BlockType.GOLD_INGOT,
    name: '金锭',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'gold_ingot'
    }
  },
  [BlockType.DIAMOND]: {
    id: BlockType.DIAMOND,
    name: '钻石',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'diamond'
    }
  },
  [BlockType.RAW_IRON]: {
    id: BlockType.RAW_IRON,
    name: '粗铁',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'raw_iron'
    }
  },
  [BlockType.RAW_GOLD]: {
    id: BlockType.RAW_GOLD,
    name: '粗金',
    solid: false,
    properties: {
      hardness: 0,
      drops: [],
      transparent: true,
      lightLevel: 0
    },
    textures: {
      sides: 'raw_gold'
    }
  }
};

export function getBlock(type: BlockType): Block {
  const block = BLOCK_REGISTRY[type];
  if (!block) {
    // 返回默认的空气方块
    return BLOCK_REGISTRY[BlockType.AIR]!;
  }
  return block;
}